/**
 * @Author : SL
 * @Date : 2019/5/30
 * @Version :1.0
 * @Last Modified by : SL
 * @Last Modified time : 2019/5/30
 **/
const {loginCheck} = require('../controller/user')
const {SuccessModel, ErrorModel} = require('../model/resModel')

const handleUserRouter = (req, res) => {
    const method = req.method

    //登录
    if (method === 'POST' && req.path === '/api/user/login') {
        const {username, password} = req.body
        const result = loginCheck(username, password)
        return result.then(data => {
            if (data.username) {
                return new SuccessModel()
            }
            return new ErrorModel('登陆失败')
        })
        // if (result) {
        //     return new SuccessModel()
        // }
        // return new ErrorModel('登陆失败')
    }
}

module.exports = handleUserRouter